package com.bw.educate.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bw.educate.client.CourseRes;
import com.bw.educate.common.ResponseResult;
import com.bw.educate.entity.EduCourseSection;
import com.bw.educate.entity.EduRes;
import com.bw.educate.service.IEduCourseSectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 在线教育-五组
 * @since 2020-08-12
 */
@RestController
@RequestMapping("eduCourseSection")
public class EduCourseSectionController {

    @Autowired
    private IEduCourseSectionService sectionService;
    @Autowired
    private CourseRes courseRes;


    @GetMapping("/getres/{cid}")
    public ResponseResult getres(@PathVariable("cid")long cid){
        ResponseResult result = ResponseResult.SUCCESS();
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("COURSE_ID",cid);
//        queryWrapper.eq("NODE_TYPE","课件");
        List<EduCourseSection> list = sectionService.list(queryWrapper);
        List lists=new ArrayList<>();
        for (EduCourseSection s:list){
            Long aLong = new Long(s.getResId());
            EduRes res = courseRes.findResById(aLong);
            res.setTag(s.getNodeName());
            lists.add(res);
        }
        result.setResult(lists);
        return result;

    }
}
